package org.androidpush.client;

import android.util.Log;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;

/**
 * Created by huang on 2017/4/21 0021.
 */
public class ChatMsgIQProvider implements IQProvider {

    public ChatMsgIQProvider() {
    }

    @Override
    public IQ parseIQ(XmlPullParser parser) throws Exception {

        ChatMsgIQ chatMsgIQ = new ChatMsgIQ();
        for (boolean done = false; !done; ) {
            int eventType = parser.next();
            Log.d("ChatMsgIQProvider eventType", Integer.toString(eventType));
            if (eventType == 2) {
                if ("chatfrom".equals(parser.getName())) {
                    chatMsgIQ.setFromuser(parser.nextText());
                }
                if ("chatto".equals(parser.getName())) {
                    chatMsgIQ.setTouser(parser.nextText());
                }
                if ("chatdate".equals(parser.getName())) {
                    chatMsgIQ.setDate(parser.nextText());
                }
                if ("message".equals(parser.getName())) {
                    chatMsgIQ.setMessage(parser.nextText());
                }
                if ("msgtype".equals(parser.getName())) {
                    chatMsgIQ.setMsgtype(parser.nextText());
                }
                if ("uuid".equals(parser.getName())) {
                    chatMsgIQ.setUuid(parser.nextText());
                }
            } else if (eventType == 3
                    && "chatmsg".equals(parser.getName())) {
                done = true;
            }
        }
        return chatMsgIQ;
    }
}
